#include <utility>
#include <stdio.h>
#include <functional>
#include <memory>
#include <string>
#include <vector>
#include <atomic>
#include <iostream>
#include "net/tcp_server.hpp"
#include "net/io_service_pool.hpp"
#include "base/logger.h"

using namespace easyasio::net;
void onConnection(const TcpConnectionPtr& conn)
{
    if (conn->connected())
    {
        conn->setTcpNoDelay(true);
    }
}

void onMessage(const TcpConnectionPtr& conn, Buffer* buf)
{
    conn->send(std::string(buf->peek(), buf->readableBytes()));
}

int main(int argc, char* argv[])
{
    if (argc < 4)
    {
        fprintf(stderr, "Usage: server <address> <port> <threads>\n");
    }
    else
    {
        //LOG_INFO << "pid = " << getpid() << ", tid = " << CurrentThread::tid();
        //Logger::setLogLevel(Logger::WARN);

        //const char* ip = argv[1];
        //uint16_t port = static_cast<uint16_t>(atoi(argv[2]));
        //InetAddress listenAddr(ip, port);

        int threadCount = atoi(argv[3]);
        TcpServer server(std::string(argv[1]), std::string(argv[2]), threadCount);

        server.setConnectionCallback(onConnection);
        server.setMessageCallback(onMessage);
        server.run();

        while (true)
        {
        	int a;
        	std::cin >> a;
        }
    }
}

